<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>佳运通综合平台-登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
</head>
<body class="login-bg">
<div class="login">
    <div class="message">佳运通综合平台-登录</div>
    <div id="darkbannerwrap"></div>
    <form method="post" class="layui-form">
        <input name="userName" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="userPwd" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
<!--        <input class="loginin" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">-->
        <button type="button" class="layui-btn layui-btn-fluid loginin" lay-submit lay-filter="login" style="width:100%;">
            登录
        </button>
    </form>
</div>

<script type="text/javascript">
    layui.extend({
        admin: '{/}./js/admin'
    });
    layui.use(['layer', 'form', 'admin', 'jquery', 'configs'], function () {
        var layer = layui.layer,
            form = layui.form,
            admin = layui.admin,
            config = layui.configs,
            $ = layui.jquery;

        $("body").keydown(function(event){
            if(event.keyCode===13){
                $('button.loginin').click();
            }
        });
        //监听提交
        form.on('submit(login)', function (data) {
                $.ajax({
                // url: "./json/login.json",
                url: config.baseUrl + "/platform/user/login/v1.0",
                type: "post",
                datatype: "json",
                data: {
                    userName: data.field.userName,
                    userPwd: data.field.userPwd
                },
                beforeSend: function(){
                    $('.loginin').prop('disabled',true);
                    $('.loginin').html('<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>')
                },
                success: function (result) {
                    if (result.stateCode == 0) {
                        var data = result.data;
                        if (data.isLogin === true) {
                            sessionStorage.setItem('login', data.isLogin);
                            sessionStorage.setItem('userInfos', JSON.stringify({
                                userId: data.userId,
                                userName: data.mapAuth.list[0].userName,
                                nickName: data.mapAuth.list[0].nickName,
                                roleName: data.mapAuth.list[0].roleName,
                            }));
                            sessionStorage.setItem("leftMenu", JSON.stringify(data.mapAuth));
                            sessionStorage.setItem("listOperation", JSON.stringify(data.listOperation));
                            getMenusData();
                            location.href = "/index";
                        } else { //false
                            layer.msg(result.stateMsg);
                        }
                    } else {
                        layer.msg(result.stateMsg);
                    }
                },
                complete: function(){
                    $('.loginin').prop('disabled',false);
                    $('.loginin').html('登录')
                }
            });
            return false;
        });
        function getMenusData() {
            $.ajax({
                url: config.motorBaseUrl + "/sys/getMeun/v1.0",
                type: "post",
                datatype: "json",
                data: {},
                success: function (result) {
                    if (result.stateCode == 0) {
                        sessionStorage.setItem("menulist", JSON.stringify(result.data));
                    } else {
                        layer.msg(result.stateMsg);
                    }

                }
            })
        }
    });
</script>
<!-- 底部结束 -->
</body>
</html>
